//
//  MoveCarPrintViewController.m
//  carcareIOS
//
//  Created by 王然 on 16/9/19.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "MoveCarPrintViewController.h"

@interface MoveCarPrintViewController ()

@property (nonatomic , strong) UIImageView * imageV;

@property (nonatomic , strong) UIView * headBlackV;

@end

@implementation MoveCarPrintViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"打印预览";
    
    [self.view addSubview:self.headBlackV];
    
    self.view.backgroundColor = COLOR_HEXSTRING(@"#272727");
    [self createUI];
}
- (void)createUI
{
    CGFloat imageVY = 11 * __MAIN_RATIO_375;
    CGFloat imageVX = 21 * __MAIN_RATIO_375;
    CGFloat imageVH = 470 * __MAIN_RATIO_375;
    self.imageV = [[UIImageView imageViewWithFrame:CGRectMake(imageVX, imageVY, __MAIN_WIDTH - imageVX * 2, imageVH) image:nil] setupOnView:self.view];
    self.imageV.contentMode = UIViewContentModeScaleAspectFit;
    self.imageV.backgroundColor = [UIColor whiteColor];
    if(self.iconImage)[self.imageV setImage:self.iconImage];
    CGFloat tipsLY = 10 * __MAIN_RATIO_375;
    UILabel * tipsL = [[[UILabel labelWithFrame:CGRectMake(self.imageV.left, self.imageV.bottom + tipsLY, self.imageV.width, 19) font:FONT_DEFAULT_Light(13) text:@"A4纸打印预览" textColor:COLOR_HEXSTRING(@"#6c6c6c")] setupOnView:self.view] labelResetTextAlignment:NSTextAlignmentCenter];
    
    CGFloat bottomBtnH = 45;
    CGFloat bottomBtnX = 17 * __MAIN_RATIO_375;
    CGFloat bottomBtnY = (__MAIN_HEIGHT_64 - tipsL.bottom - tipsLY - bottomBtnH) / 2 + tipsLY + tipsL.bottom;
     __weak __typeof(self) wself = self;
    [[[[UIButton buttonWithFrame:CGRectMake(bottomBtnX, bottomBtnY, __MAIN_WIDTH - bottomBtnX * 2, bottomBtnH) title:@"保存到手机" textColor:[UIColor whiteColor] font:FONT_DEFAULT_Light(15) click:^{
        [wself printLookSaveImageBtn:wself.imageV.image];
    }] setupOnView:self.view] resetBorderWidth:1 borderColor:[UIColor whiteColor]] resetCornerRadius:2];
}
- (void)setIconImage:(UIImage *)iconImage
{
    _iconImage = iconImage;
}
// 打印预览 页面 保存到手机按钮
- (void)printLookSaveImageBtn:(UIImage *)image
{
    if(image)UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
//保存图片到相册的回调函数
-(void) image: (UIImage *)image didFinishSavingWithError: (NSError *)error
  contextInfo: (void *) contextInfo{
    
    if (error == nil) {
        [AlertMgr showShortTextTips:@[@"已存入手机相册"]];
    }
    else {
        [error.userInfo objectForKey:@""];
        if (!SYSTEMHELPER.isOpenMedia) {
            TipsView *tips = [TipsView textTipsWithTitle:LOCSTRING(@"tips_media_no_open") lightTitles:@[LOCSTRING(@"tips_media_open_1"),LOCSTRING(@"tips_media_open_2")]];
            [tips addOKButton:LOCSTRING(@"ok") clickOK:^{
                [AlertMgr dismiss:TYPE_VIEW_ALERT];
            }];
            [AlertMgr showView:tips];
            return;
        }else [AlertMgr showShortTextTips:@[@"存入相册失败"]];
    }
}
- (UIView *)headBlackV
{
    if (!_headBlackV) {
        _headBlackV = [[UIView viewWithFrame:CGRectMake(0, -64, __MAIN_WIDTH, 70)] resetBackgroundColor:COLOR_HEXSTRING(@"#272727")];
    }
    return _headBlackV;
}
#pragma mark - nav
-(UIColor *)navBackgroundColor{
    return [UIColor clearColor];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
